class Solution {
    public:
        bool isMatch(string s, string p) {
            int m = s.size(),n= p.size();
            s = " "+s;
            p = " "+p;
            vector<vector<bool>> dp(m+1,vector<bool>(n+1));
            dp[0][0] = true;
            for(int i = 1 ; i < n+1 ; i++){
                if(p[i] == '*') dp[0][i] =true;
                else break;
            }
            for(int i = 1 ; i < m+1 ; i++){
                for(int j = 1 ; j < n+1 ;j++){
                    if(p[j] =='?'){
                        dp[i][j] = dp[i-1][j-1];
                    }else if(p[j] == '*'){
                        //*可匹配空串或者多个字符串
                        dp[i][j] = dp[i][j-1] || dp[i-1][j];
                    }else{
                        if(s[i] == p[j]) dp[i][j] = dp[i-1][j-1];
                        else dp[i][j] = false;
                    }
                }
            }
            return dp[m][n];
        }
    };